<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>main</title>
		<link rel="stylesheet" type="text/css" href="css/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="css/hui.css" />
		<link rel="stylesheet" type="text/css" href="css/my.css" />
		<link rel="stylesheet" type="text/css" href="css/photoswipe.css" />
		<link rel="stylesheet" type="text/css" href="css/animate.min.css" />
		<link rel="stylesheet" type="text/css" href="css/swiper.css" />
		<link rel="stylesheet" type="text/css" href="css/main_R.css" />
		<link rel="stylesheet" type="text/css" href="Video/videohls/video.css">
		<style>
			.video-controls {
				position: absolute;
				bottom: 0;
				left: 0;
				width: 100%;
				background: rgba(0, 0, 0, .4);
				z-index: 1;
				height: 100%;
			}
			
			.video-controls .icon {
				color: white;
				float: right;
			}
			
			.icon-bigbtn {
				position: absolute;
				font-size: 2.5em;
				height: 1.5em;
				width: 1.5em;
				border-radius: 1.5em;
				line-height: 1.4em;
				left: 50%;
				margin-left: -.75em;
				top: 50%;
				margin-top: -.75em;
				z-index: 9;
			}
			
			.icon-bigbtn img {
				width: 100%;
				height: 100%
			}
			
			.video-js .vjs-time-control {
				display: block;
			}
			
			.video-js .vjs-remaining-time {
				display: none;
			}
			
			#hui-back:before {
				content: "\e6a5";
				font-size: 15px;
				color: #464646;
			}
			
			
			
			
			
			
			
			
			
			.mui-card{
				
			}
			.base_index_list {
			  display: flex;
			  flex-wrap: wrap;
			}
			.base_index_list li {
			  width: 45%;
			  height: 80px;
			  background: #fff;
			  border-radius: 5px;
			  margin: 15px 0 0 3.3%;
			  display: flex;
			  flex-wrap: wrap;
			  position: relative;
			}
			.base_index_list li .base_index_name {
			  width: 65%;
			  height: 100%;
			  display: flex;
			  flex-direction: column;
			  align-items: center;
			}
			.base_index_list li .base_index_name .name {
			  /*line-height: 30px;*/
			 box-sizing: border-box;
			 padding: 8px 0 0 0;
			  color: #606060;
			  text-align: center;
				word-break:normal;
				white-space:pre-warp;
				word-wrapL:break-word;
				height: 30%;
			}
			.base_index_list li .base_index_name .unit {
			  font-size: 16px;
			  /*line-height: 36px;*/
			  color: #255ca9;
			}
			.base_index_list li .base_index_icon {
			  width: 35%;
			  height: 100%;
			  display: flex;
			  align-items: center;
			}
			.base_index_list li .base_index_icon img {
			  width: auto;
			  height: 70%;
			  margin-top: 15px;
			}
			.base_index_list li:last-child {
			  width: 100%;
			  height: 5px;
			  background: rgba(0, 0, 0, 0);
			}
			.base_index_list li .errorTips{
				height: 20px; 
				width: 100%; 
				display: none;
				background: rgba(0,0,0,.5); 
				position: absolute; 
				bottom: 0px; 
				left: 0;
			}
			.base_index_list li .errorTips p{
				line-height: 20px; 
				text-align: center; 
				font-size: 14px; 
				color: #fff;
			}
			

			.item_div {
				height: 60px;
				display: flex;
				flex-direction: row;
				align-items: center;
			}
			
			.item_div img {
				width: 24px;
				height: 24px
			}
			
			
			.item_box_p1 {
				line-height: 60px;
				padding-left: 10px;
				color: #666666;
			}
			
			.item_box_p2 {
				line-height: 60px;
				flex-grow: 1;
				text-align: right;
				padding-right: 10px;
				color: #666666;
			}
			.item_box_p2 .active{
				border: 1px solid #000;
			}
			.item_box_p2 .cur{background:#06c;color:#fff;}
			.hui-icons {
				color: #666666;
			}
		</style>
	</head>

	<body>
		<div id="datas" class="hui-wrap">
			<div class="topHeight"></div>

			<div class="info_nav">
				<span class="hui-icons hui-icons-menu" onclick="showMenu()" style=""></span>
				<h2 class="base_name" style=""></h2>
				<div class="user_head" style="" onclick="openSetting()">
					<img src="img/head_icon.png" alt="" style="" />
				</div>
			</div>

			<div class="topBanner" style="">
				<div id="swipe_Con" style="">
					<div class="swiper-container" style="">
						<div class="swiper-wrapper">

						</div>

					</div>
				</div>
				<div id="video_Con" style="">
					<!--<img id="play_Button" src="img/play_button.png" alt="" />
					<img id="video_Cover" src="img/videoFile.png" alt="" />-->

					<!--<video id="my-video" class="video-js vjs-default-skin" controls preload></video>-->

					<!--<video id="my-video" class="video-js vjs-default-skin vjs-big-play-centered" controls x-webkit-airplay="allow" poster="" webkit-playsinline playsinline x5-video-player-type="h5" x5-video-player-fullscreen="true" preload="auto">
	    
					</video>-->
					<div class="video-controls" id="videobg">
						<img id="video_Cover" src="img/videoFile.png" alt="" />
						<span class="icon iconfont icon-bofang icon-bigbtn" id="videoplay">		
							<img id="play_Button" src="img/play_button.png" alt="" />
						</span>
					</div>
				</div>
				<section class="ImgVideoTab" style="">
					<span class="Video_Button">视　频</span>
					<span class="Img_Button active">图　片</span>
					<span class="Base_Position">位　置</span>
				</section>
				<span class="ImgNum"><span class="ImgIndex">1</span> / <span class="ImgTotal">4</span></span>
			</div>

			<!---->
			<div class="base_index" style="margin: 0;">
		    	<ul class="mui-table-view">
					<li class="mui-table-view-cell mui-collapse mui-active" v-for="accordion in accordionList">
						<a class="mui-navigate-right" href="#" v-html="accordion" style="font-size: 18px;"></a>
						<div class="mui-collapse-content">
							<ul class="base_index_list">
				                <li v-for="detail in list" @click="onDetailSelected(detail)" style="width: 45%; margin: 10px 2%; border: 1px solid #000; float: left;">
									<div class="base_index_name" style="">
										<p class="name" v-html="HandleName(detail.TargetName)" style=""></p>
										<p style="color: #606060;height: 25%; padding: 0 0 0 0;" v-html="HandleName2(detail.TargetName)"></p>
										<p class="unit" v-text="getValue(detail)" style=""></p>
									</div>
		
									<div class="base_index_icon" style="">
										<img :src="getIcon(detail)" alt="" style="" />
									</div>
									<div :class="getErrorTips(detail.State)" style="">
										<p style="">指标数据异常</p>
									</div>
								</li>
								<li style=""></li>
				            </ul>
						</div>
					</li>
					<li class="mui-table-view-cell mui-collapse mui-active" v-for="accordion in 1" v-if="equipmentList.length!=0">
						<a class="mui-navigate-right" href="#" style="font-size: 18px;">设备控制</a>
						<div class="mui-collapse-content">
							<template v-for="(column,index) in equipmentList">
								<div class="item_div">
									<p class="item_box_p1"style="width: 130px;">{{column.SensorName}}</p>
									<div class="item_box_p2" v-html="getSwitchBox(column)">
			
									</div>
								</div>
							</template>
						</div>
					</li>
					<li class="mui-table-view-cell" @click="ControlsV(1)">
						<a class="mui-navigate-right" href="#" style="font-size: 18px;">条件控制计划</a>
						<div class="mui-collapse-content">
						        
						</div>
					</li>
					<li class="mui-table-view-cell" @click="ControlsV(2)">
						<a class="mui-navigate-right" href="#" style="font-size: 18px;">时间控制计划</a>
						<div class="mui-collapse-content">
						        
						</div>
					</li>
				</ul>
		    </div>
			<!--<div class="base_index" style="">

				<div class="base_index_container" style="">
					<ul class="base_index_list" style="">
						<li v-for="detail in list" @click="onDetailSelected(detail)" style="">

							<div class="base_index_name" style="">
								<p class="name" v-html="HandleName(detail.TargetName)" style=""></p>
								<p style="color: #606060;height: 25%; padding: 8px 0 0 0;" v-html="HandleName2(detail.TargetName)"></p>
								<p class="unit" v-text="getValue(detail)" style=""></p>
							</div>

							<div class="base_index_icon" style="">
								<img :src="getIcon(detail)" alt="" style="" />
							</div>
							<div :class="getErrorTips(detail.State)" style="">
								<p style="">指标数据异常</p>
							</div>
						</li>
						<li style=""></li>
					</ul>
				</div>
				<div class="sureserve" style="">sensor@sureserve.cn</div>
			</div>-->

			<!--侧边菜单栏-->
			<div class="hui-slide-menu" style="">
				<ul>
					<li style="height: 32px;line-height: 28px;">
						<div class="backBtn" id="hui-back" style="width: 100%; height: 100%; line-height: 28px;">
							<i style="line-height: 24px; color: #464646;">返回</i>
						</div>
					</li>
					<li v-for="(column,index) in getFilterColumn()" v-if="column.display==1" style="">
						<div :class="getLeftClass(index,column.Id,column.Name,column.Lat,column.Lng)" @click="onColumnSelected(column,index)">
							<div :class="getStateBGC(column.State)"></div>
							<b v-html="getState(column.State)" :class="getStateBGC(column.State)"></b>
							<p style="">{{column.Name}}</p>
						</div>
					</li>
					<li style="height: 22px; border: 0;"></li>
				</ul>
			</div>
			<div id="mask" style="display: none;" onclick="hideMenu()"></div>
		</div>

		<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
			<div class="pswp__bg"></div>
			<div class="pswp__scroll-wrap">
				<div class="pswp__container" style="overflow:visible;">
					<div class="pswp__item"></div>
					<div class="pswp__item"></div>
					<div class="pswp__item"></div>
				</div>
				<div class="pswp__ui pswp__ui--hidden">
					<div class="pswp__top-bar">
						<div class="pswp__counter"></div>
						<button class="pswp__button pswp__button--close" title="关闭"></button>
						<div class="pswp__preloader">
							<div class="pswp__preloader__icn">
								<div class="pswp__preloader__cut">
									<div class="pswp__preloader__donut"></div>
								</div>
							</div>
						</div>
					</div>
					<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
						<div class="pswp__share-tooltip"></div>
					</div>
					<div class="pswp__caption">
						<div class="pswp__caption__center"></div>
					</div>
				</div>
			</div>
		</div>

		<script src="js/func/hui.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/func/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/func/jq.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/func/vue.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/obj/photoswipe.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/obj/photoswipe-ui-default.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/obj/my.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/obj/update.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript" src="./js/MapJs/shi.js"></script>
		<script src="js/func/swiper.js" type="text/javascript" charset="utf-8"></script>

		<script type="text/javascript">
			var cityName = getValue("cityName");
				var shiJson={
			  	"1825": {
				    "1826": "长沙",
				    "1836": "株洲",
				    "1846": "湘潭",
				    "1852": "衡阳",
				    "1865": "邵阳",
				    "1878": "岳阳",
				    "1888": "常德",
				    "1898": "张家界",
				    "1903": "益阳",
				    "1910": "郴州",
				    "1922": "永州",
				    "1934": "怀化",
				    "1947": "娄底",
				    "1953": "湘西"
			  	},
			  	"3121": {
				    "3122": "乌鲁木齐",
				    "3131": "克拉玛依",
				    "3136": "吐鲁番",
				    "3140": "哈密",
				    "3144": "昌吉",
				    "3152": "博尔塔拉",
				    "3156": "巴音郭楞",
				    "3166": "阿克苏",
				    "3176": "克孜勒苏",
				    "3181": "喀什",
				    "3194": "和田",
				    "3203": "伊犁",
				    "3214": "塔城",
				    "3222": "阿勒泰",
				    "3230": "石河子",
				    "3232": "阿拉尔",
				    "3234": "图木舒克",
				    "3236": "五家渠"
			  	},
  			};

			function showMenu() {
				hui('.hui-slide-menu').css({
					display: 'block',
					top: '20px'
				});
				hui('#mask').css({
					display: 'block'
				});
			}

			function hideMenu() {
				hui('.hui-slide-menu').css({
					display: 'none'
				});
				hui('#mask').css({
					display: 'none'
				});
			}

			//刷新主界面
			function refresh() {
				printLog("主界面开始刷新");
				datas.userInfo = getUserInfo();
				getColumns();
			}
			//刷新网管列表
			function refreshColumns() {
				printLog("刷新网关列表");
				getColumns();
			}
			var mySwiper
			var SwiperNum = 1;

			function initSwiper() {
				mySwiper = new Swiper('.swiper-container', {

					loop: false,
					pagination: {
						el: '.swiper-pagination',
					},
					noSwiping: true,
					on: {
						slideChangeTransitionEnd: function() {
							//alert(this.activeIndex);//切换结束时，告诉我现在是第几个slide
							hui('.ImgIndex').html(this.activeIndex + 1);
						},
					},
				})
				SwiperNum++;
			}

			hui.ready(function() {
				//轮播图控制
				initSwiper();

				//默认第一次调用基地数据请求 
				getColumns2();
				hui.plusReady(function() {

					checkUpdate(true);
				})

			})
			var Sensor_Name = ''
			var myPlayer, IsPlay = true;
			var datas = new Vue({
				el: '#datas',
				data: {
					userInfo: getUserInfo(),
					accordionList: [],
					columns: [],
					list: [],
					equipmentList: [],
					ImgContainer: [],
					VideoContainer: [],
					selectListIndex: 0,
				},
				methods: {
					//选中左侧基地
					onColumnSelected: function(column, index) {
						console.log('===========' + column);
						this.selectListIndex = index;
						getSensorList(column);
					},
					//左侧基地选中class
					getLeftClass: function(index, columnId, columnName, Lat, Lng) {

						if(this.selectListIndex == index) {
							//存入当前基地位置  打开基地位置页面后 让当前基地居中
							localStorage.setItem('columnLat', Lat);
							localStorage.setItem('columnLng', Lng);

							console.log("左边列表选中666:" + index);
							Sensor_Base = columnId;
							Sensor_Name = columnName;
							console.log("左边列表选中Id:" + Sensor_Base);
							console.log("左边列表选中的基地名字是:" + Sensor_Name);
							hideMenu();
							hui('.base_name').html(Sensor_Name)
						}
						return index == this.selectListIndex ? "column_div selected" : "column_div";
					},
					getState: function(state) {
						return state == 0 ? "正常" : state == -1 ? "缺电" : state == 1 ? "延时" : state;
					},
					getStateBGC: function(state) {
						return state == 0 ? "cur0" : state == -1 ? "cur-1" : state == 1 ? "cur1" : state;
					},
					getErrorTips: function(state) {
						return state == 0 ? "errorTips" : "errorTips block";
					},
					//过滤掉不要显示 display不为1的基地
					getFilterColumn: function() {
						return this.columns.filter(function(column) {
							var fistC = column.display == 1;
							return fistC;
						});

					},
					HandleName: function(name) {

						if(name == '土壤PH') {
							return name
						}
						if(name != '土壤PH') {
							var reg = /[\u4e00-\u9fa5]/g;
							var chinaName = name.match(reg).join("");
							return chinaName
						}
					},
					HandleName2: function(name) {

						if(name == '土壤PH') {
							//return name
						}
						if(name != '土壤PH') {
							var reg = /[\u4e00-\u9fa5]/g;
							var chinaName = name.replace(reg, "");

							return chinaName
						}
					},
					onDetailSelected: function(detail) {
						console.log(detail)
						var url = "main_Detail.html?sid=" + detail.Id;
						url += "&tid=" + detail.TargetId;
						url += "&data=" + getFloat(format(detail.MeasureData, '0'), 3);
						url += "&name=" + detail.TargetName;
						url += "&unit=" + detail.TargetUnit;
						url += "&base=" + Sensor_Base;
						url += "&sensorN=" + Sensor_Name;
						console.log(url);
						hui.open(encodeURI(url), {}, true, {});
					},
					// 获取头像
					getHead: function() {
						console.log('header:' + JSON.stringify(this.userInfo));
						var avatar = ""
						if(this.userInfo && this.userInfo.avatar) {
							avatar = baseURL() + this.userInfo.avatar;
						} else {
							avatar = "img/head_icon.png";
						}
						return avatar;
					},
					//获得右侧指标图标
					getIcon: function(column) {
						var type = column.TargetName;
						var icon = getIconByTarget(type);

						return icon;
					},
					getValue: function(detail) {
						var tmp = format(detail.MeasureData, '0');
						var type = detail.TargetName;
						return getFloat(tmp, 3) + detail.TargetUnit;
					},
					getSwitchBox: function(column) {
						console.log(column)
						/*var html = '<button type="button" style="margin: 0 2px;" class="hui-button hui-button-small hui-fl" data-Stid="'+column.Id+'" data-GateWayId="'+column.GateWayId+'" data-SensorCode="'+column.SensorCode+'" data-SensorId="'+column.SensorId+'" onclick="Controls(this, 2)">展开</button> ' +
									'<button type="button" style="margin: 0 2px;" class="hui-button hui-button-small hui-fl" data-Stid="'+column.Id+'" data-GateWayId="'+column.GateWayId+'" data-SensorCode="'+column.SensorCode+'" data-SensorId="'+column.SensorId+'" onclick="Controls(this,0)">停止</button>'+ 
									'<button type="button" style="margin: 0 2px;" class="hui-button hui-button-small hui-fl" data-Stid="'+column.Id+'" data-GateWayId="'+column.GateWayId+'" data-SensorCode="'+column.SensorCode+'" data-SensorId="'+column.SensorId+'" onclick="Controls(this,3)">收缩</button>';*/
						var html = '';			
						if(column.State == 2){
							html = '<button type="button" style="margin: 0 2px;" class="hui-button hui-button-small hui-fl cur" data-Stid="'+column.Id+'" data-GateWayId="'+column.GateWayId+'" data-SensorCode="'+column.SensorCode+'" data-SensorId="'+column.SensorId+'" onclick="Controls(this, 2)">展开</button> ';
						}else{
							html = '<button type="button" style="margin: 0 2px;" class="hui-button hui-button-small hui-fl" data-Stid="'+column.Id+'" data-GateWayId="'+column.GateWayId+'" data-SensorCode="'+column.SensorCode+'" data-SensorId="'+column.SensorId+'" onclick="Controls(this, 2)">展开</button> ';
						}
						if(column.State == 0){
							html += '<button type="button" style="margin: 0 2px;" class="hui-button hui-button-small hui-fl cur" data-Stid="'+column.Id+'" data-GateWayId="'+column.GateWayId+'" data-SensorCode="'+column.SensorCode+'" data-SensorId="'+column.SensorId+'" onclick="Controls(this,0)">停止</button>';
						}else{
							html += '<button type="button" style="margin: 0 2px;" class="hui-button hui-button-small hui-fl" data-Stid="'+column.Id+'" data-GateWayId="'+column.GateWayId+'" data-SensorCode="'+column.SensorCode+'" data-SensorId="'+column.SensorId+'" onclick="Controls(this,0)">停止</button>';
						}
						if(column.State == 3){
							html += '<button type="button" style="margin: 0 2px;" class="hui-button hui-button-small hui-fl cur" data-Stid="'+column.Id+'" data-GateWayId="'+column.GateWayId+'" data-SensorCode="'+column.SensorCode+'" data-SensorId="'+column.SensorId+'" onclick="Controls(this,3)">收缩</button>';
						}else{
							html += '<button type="button" style="margin: 0 2px;" class="hui-button hui-button-small hui-fl" data-Stid="'+column.Id+'" data-GateWayId="'+column.GateWayId+'" data-SensorCode="'+column.SensorCode+'" data-SensorId="'+column.SensorId+'" onclick="Controls(this,3)">收缩</button>';
						}
						
						
						

						if(column.SensorType  != 23) {
							if(column.State == 1){
								html = '<button type="button" style="margin: 0 2px;" class="hui-button hui-button-small hui-fl cur" data-Stid="'+column.Id+'" data-GateWayId="'+column.GateWayId+'" data-SensorCode="'+column.SensorCode+'" data-SensorId="'+column.SensorId+'" onclick="Controls(this, 1)">开启</button>'; 
							}else{
								html = '<button type="button" style="margin: 0 2px;" class="hui-button hui-button-small hui-fl" data-Stid="'+column.Id+'" data-GateWayId="'+column.GateWayId+'" data-SensorCode="'+column.SensorCode+'" data-SensorId="'+column.SensorId+'" onclick="Controls(this, 1)">开启</button>';
							}
							
							if(column.State == 0){
								html += '<button type="button" style="margin: 0 2px;" class="hui-button hui-button-small hui-fl cur" data-Stid="'+column.Id+'" data-GateWayId="'+column.GateWayId+'" data-SensorCode="'+column.SensorCode+'" data-SensorId="'+column.SensorId+'" onclick="Controls(this,0)">停止</button>'; 
							}else{
								html += '<button type="button" style="margin: 0 2px;" class="hui-button hui-button-small hui-fl" data-Stid="'+column.Id+'" data-GateWayId="'+column.GateWayId+'" data-SensorCode="'+column.SensorCode+'" data-SensorId="'+column.SensorId+'" onclick="Controls(this,0)">停止</button>'; 
							}
							/*html = '<button type="button" style="margin: 0 2px;" class="hui-button hui-button-small hui-fl" data-Stid="'+column.Id+'" data-GateWayId="'+column.GateWayId+'" data-SensorCode="'+column.SensorCode+'" data-SensorId="'+column.SensorId+'" onclick="Controls(this, 1)">开启</button>'+  
									'<button type="button" style="margin: 0 2px;" class="hui-button hui-button-small hui-fl" data-Stid="'+column.Id+'" data-GateWayId="'+column.GateWayId+'" data-SensorCode="'+column.SensorCode+'" data-SensorId="'+column.SensorId+'" onclick="Controls(this,0)">停止</button>';*/
						}

						return html;
					},
					ControlsV: function(type){
						/*hui.confirm('', ['取消','确定'], function(){
					        console.log('确认后执行...');
					    },function(){
					        console.log('取消后执行...');
					    });*/
					   	type == 1 ? hui.open("conditionControl.html?name=", {}, true, {}) : hui.open("Controlplan.html?name=", {}, true, {});
						//hui.open("Controlplan.html?name=", {}, true, {});
					},
					ControlsClass: function(state){
						alert(111);
						console.log(state)
					}
				}
			})

			function Controls(that, state){
				//console.log($(that))
				let tipText = '您确定要' + $(that).text() + $(that).parents('.item_box_p2').siblings('.item_box_p1').text() + '吗？';
				
				//$(that).addClass('active').siblings('butten').removeClass('active');
				 hui.confirm(tipText, ['取消','确定'], function(){
			        var param = {
						gid: $(that).attr('data-GateWayId'),
						sensorcode: $(that).attr('data-SensorCode'),
						state: state,
					};
					console.log(param)
					postJson('http://sensor.sureserve.cn/interfaces/control_handler.ashx?action=yy_control', param, function(ret) {
						console.log(ret)
						if(ret.result == 0){
							//hui.upToast('操作成功 !');
								
							var param1 = {
								gid: $(that).attr('data-GateWayId'),
								stid: $(that).attr('data-Stid'),
							}
							
							console.log(param1)
							targetStatenum = 1;
							targetState(param1, null, that)
							hui.loading('连接服务器成功，正在操作中，请稍等...');
						}
					})
			    },function(){
			        hui.toast('取消操作');
			    });
				
				
			}
			
			
			let targetStatenum = 1;
			function targetState(param, State, that) {
				hui.loading('连接服务器成功，正在操作中，请稍等...');
				setTimeout(function(){
					postJson('http://sensor.sureserve.cn/interfaces/target_handler.ashx?action=target_state',param, function(results){
						
						console.log(results)
						console.log(State)
						if(State != null){
							console.log(State)
							console.log(results.data.State)
							if(State != results.data.State){
								console.log($(that))
								$(that).addClass('cur').siblings('button').removeClass('cur')
								console.log('成功')
								hui.alert('操作成功！');
								targetStatenum = 4;
							}else{
								if(targetStatenum == 3){
									hui.alert('操作失败！')
								}
								console.log('失败')
							}
						}
						
						if(targetStatenum < 3){
							targetState(param, results.data.State, that)
							targetStatenum++;
						}
					})
				},4000)
			}
			
			
			function HandleDate(){
				var date = new Date().Format('yyyy-MM-dd HH:mm:ss')
				console.log(date)
			}
			

			function openSetting() {
				hui.open("account.html", {}, true, {});
				//				hui.open("base_Position.html", {}, true, {});
			}

			/*
			 * 湖南各市基地分类 
			 * */
			var Container_Base = []; // 当前市 基地分类容器

			//基地数据请求
			function getColumns2() {
				//var userId = getValue('loginId');
				var userId = 1;
				var url = newBaseUrl() + "/displaydirectory/getdisplaydirectorylistbyuser?userid=" + userId;
				hui.loading("正在获取数据...");
				hui.get(
	    			url,
	    			function(res){
	    				hui.closeLoading();
						localStorage.setItem("columns", JSON.stringify(data.result));
	    				
	    				let result = JSON.stoString(res);
	    				
						var showFirst = false;
						console.log(result);
						console.log(re2.msg);
						console.log(res.result);
	    				//getCityBase2(data.result, showFirst); //调用渲染方法
	    				
	    				
	    			},
					function(e){
						console.log(e)
					},
				)	
				
			}
			function getColumns() {
				var userId = getUserId();

				var url = baseURL() + "/gateway_handler.ashx?action=gateway_user";
				//var url = baseURL() + "/gateway_handler.ashx?action=gateway_multiple"; 
				//				var url = 'http://124.232.165.110:38081/interfaces/gateway_handler.ashx?action=gateway_user';		    

				var param = {
					uid: userId
				};

				console.log('--获取基地数据--');
				hui.loading("正在获取数据...");
				postJson(url, param, function(ret) {
					Container_Base = []; //每次请求数据之前清除上次残留的数据 否则会造成数据异常
					//console.log(JSON.stringify(ret));
					localStorage.setItem("columns", JSON.stringify(ret.data));
					SwiperNum = 1;
					if(ret.data.length > 0) {
						var showFirst = false;
						for(var i = 0; i < ret.data.length; i++) { //遍历所有数据 分离新疆  湖南基地
							var d = ret.data[i];
							var DeepPath = d.DeepPath.split('/')
							//DeepPath 存在两种情况  为空用第二个开始的ID 
							if(DeepPath[0] == '') {
								//								console.log(shiJson[DeepPath[1]][DeepPath[2]]);
								if(shiJson[DeepPath[1]][DeepPath[2]] == cityName) {
									Container_Base.push(d);
								}
							} else {
								//								console.log(shiJson[DeepPath[0]][DeepPath[1]]);
								if(shiJson[DeepPath[0]][DeepPath[1]] == cityName) {
									Container_Base.push(d);
								}
							}

							//console.log(JSON.stringify(d));
						}

						getCityBase(Container_Base, showFirst); //调用渲染方法

						setTimeout(function() {
							datas.selectListIndex = 0;
						}, 500)
					}
				});
			}

			//各市基地渲染方法
			function getCityBase2(CityBase, showFirst) {
				console.log(CityBase);
				
				datas.columns = CityBase;
				getSensorList(CityBase[0]);
			}
			function getCityBase(CityBase, showFirst) {
				datas.columns = CityBase;
				//				console.log('=======' + JSON.stringify(datas.columns));
				localStorage.setItem("basePosition", JSON.stringify(CityBase));
				for(var c = 0; c < CityBase.length; c++) { //遍历各市基地
					if(CityBase[c].display == 1 && !showFirst) {
						showFirst = true;
						getSensorList(CityBase[c]);
					}
				}
			}

			var caremaParams = [];
			//获取基地摄像头信息
			function getCameraInfo(column) {
				console.log(column);
				localStorage.setItem('detailColumn', JSON.stringify(column));
				var url = baseURL() + "/gateway_handler.ashx?action=gateway_multiple";
				console.log(url);
				var columnId = column.Id;
				var param = {
					gids: columnId,
				};
				console.log(column.SerialNo);
				console.log(column.SerialNo[0]);
				let SerialNo = '';
				if(column.SerialNo[0] == '['){
					SerialNo = JSON.parse(column.SerialNo)
					console.log(SerialNo);
				}
				console.log(column.SerialNo);
				console.log(JSON.stringify(param));
				printLog(param);
				caremaParams = [];
				//hui.loading("正在获取数据...");
				/*postJson(url, param, function(ret) {
					console.log(ret)
					console.log("----摄像头返回----");
					//printLog(ret, "摄像头返回");

					var cameraStr = ret.data[0].SerialNo;
					var cameraList = JSON.parse(cameraStr);
					
					console.log(cameraList)*/
					//var params = new Array();
					for(var i = 0; i < SerialNo.length; i++) {
						console.log(SerialNo[i])
						console.log(Sensor_Name);
						caremaParams.push({
							keyWords: SerialNo[i].code,
							siteName: Sensor_Name,
							summary: SerialNo[i].name,
							title: "cameraIndexCode",
							videoType: "1"
						})
					}
					console.log(caremaParams)
					printLog(caremaParams, "摄像头返回");

					if(caremaParams.length > 0) {
						buttonIF(column.Video, column.Albums, column.VideoImg, column.SerialNo, column.ChannelNo); //调用控制图片及视屏显示方法
					} else {
						
					}

				/*}, function(e) {

				});*/
			}

			var isOpenCamera = false;
			//打开原生摄像头页面
			function openCamera() {
				
				if(!caremaParams || caremaParams.length == 0) {
					hui.toast("没有可查看的摄像头!")
					return;
				}
				if (isOpenCamera == true){
					return;
				}

				hui.loading("正在打开摄像头");
				var videoStr = JSON.stringify(caremaParams);
				var previewActivity = plus.android.runtimeMainActivity();
				Intent = plus.android.importClass('android.content.Intent');
				var intent = new Intent();
				intent.setClassName('com.sureserve.sensor', 'com.sureserve.sensor.PreviewActivity'); //io.dcloud.PandoraEntry是启动类 在线打包的默认这个
				intent.putExtra("title", Sensor_Name);
				intent.putExtra("videos", videoStr);
				previewActivity.onActivityResult = function(requestCode, resultCode, data) {
					//console.log("摄像窗口关闭返回:" + requestCode + "|" + resultCode);
					isOpenCamera= false;
					hui.closeLoading();
				}
				
				isOpenCamera = true;
				previewActivity.startActivityForResult(intent, 10010); //打开activity
			}

			//指标数据请求
			var video, output;

			function getSensorList(column) {
				console.log(column);
				getCameraInfo(column);

				buttonIF(column.Video, column.Albums, column.VideoImg, column.SerialNo, column.ChannelNo); //调用控制图片及视屏显示方法

				var columnId = column.Id;
				var timestamp = new Date().getTime();
				var url = baseURL() + "/gateway_handler.ashx?action=gateway_target_cache";
				console.log(url);
				var param = {
					gid: columnId,
					timestamp: timestamp,
					num: column.Number,
				};

				console.log(JSON.stringify(param));
				datas.list = [];
				printLog(param);
				hui.loading("正在获取数据...");
				postJson(url, param, function(ret) {
					console.log(ret)
					printLog(ret, "传感器");
					let sensorList = [], equipmentList =[];
					$.each(ret.data, function(i,v) {
						v.TargetType != 99 ? sensorList.push(v) : equipmentList.push(v);
					})
					setTimeout(function() {
						datas.accordionList = unique1(sensorList);
						datas.list = sensorList;	
						datas.equipmentList = equipmentList;
						localStorage.setItem('equipmentList', JSON.stringify(equipmentList))
						localStorage.setItem('sensorList', JSON.stringify(sensorList))
						
					}, 500);
				}, function(e) {

				});
			}

			
			function unique1(arr){
			  	var hash=[];
			  	for (var i = 0; i < arr.length; i++) {
			  		if(hash.length == 0){
			  			hash.push(arr[i].GateWayName);
			  		}
			     	if(hash.indexOf(arr[i].GateWayName)==-1){
			     		
			      		hash.push(arr[i].GateWayName);
			     	}
			  	}
			  	return hash;
			}
	
			$('.Video_Button').on('click', function() {
				$(this).show().addClass('active').siblings('span').removeClass('active');
				$('#swipe_Con').hide();
				$('.ImgNum').hide();
				$('#video_Con').show();
			})
			$('.Img_Button').on('click', function() {
				$(this).show().addClass('active').siblings('span').removeClass('active');
				$('#video_Con').hide();
				$('#swipe_Con').show();
				$('.ImgNum').show();
			})
			$('.Base_Position').on('click', function() {
				hui.open("base_Position.html", {}, true, {});
			})
			//视屏及图片显示控制方法
			function buttonIF(Video, Img, VideoImg, SerialNo, ChannelNo) {
				
				var isCamera = (caremaParams != null && caremaParams.length > 0);
				var isVideo = (Video != null && Video != '') || isCamera;
				var isImg = Img != null && Img != ''

				if((Img == null || Img == '') && !isVideo) {
					hui('.ImgIndex').html(1);
					//无图片 无视频
					$('#video_Con').hide();
					$('#swipe_Con').show();
					$('.ImgNum').show();
					$('.Video_Button').hide().removeClass('active');
					$('.Img_Button').show().addClass('active');
					mySwiper.removeAllSlides(); //删除所有已存在的slide 重新添加

					for(var i = 0; i < 3; i++) {
						mySwiper.addSlide(i, '<div class="swiper-slide"><img src="img/banner0' + (i + 1) + '.png"></div>'); //在index为1的位置插入一个slide
					}
					hui('.ImgTotal').html(3);
					ImgPreview();

				} else if((Img == null || Img == '') && isVideo) {
					//无图片 有视频
					$('#swipe_Con').hide();
					$('#video_Con').show();
					$('.ImgNum').hide();
					$('.Video_Button').show().addClass('active');
					$('.Img_Button').hide().removeClass('active');
					
					console.log("无图片有视频");
					console.log("VideoImg:" + VideoImg);

					VideoIf(Video, VideoImg, SerialNo, ChannelNo);

				} else if((Img != null || Img != '') && !isVideo) {
					//有图片 无视频
					$('#video_Con').hide();
					$('#swipe_Con').show();
					$('.ImgNum').show();
					$('.Video_Button').hide().removeClass('active');
					$('.Img_Button').show().addClass('active');

					//添加图片
					ImgIf(Img);

				} else if((Img != null || Img != '') && isVideo) {
					//有图片 有视频
					$('#swipe_Con').hide();
					$('#video_Con').show();
					$('.ImgNum').hide();
					$('.Video_Button').show().addClass('active');
					$('.Img_Button').show().removeClass('active');
					
					
					console.log("有图片有视频");
					console.log("VideoImg:" + VideoImg);
					console.log("Img:" + Img);

					//添加视频
					var imgUrl = VideoImg;
					VideoIf(Video, imgUrl, SerialNo, ChannelNo);

					//添加图片
					ImgIf(Img);

				}

			}
			//添加图片方法
			function ImgIf(Img) {
				hui('.ImgIndex').html(1);
				//添加图片
				var imgURL = Img.split('|'),
					imgHtml = '';
				console.log(imgURL);
				mySwiper.removeAllSlides(); //删除所有已存在的slide 重新添加
				//循环添加slide
				for(var i = 0; i < imgURL.length; i++) {
					console.log('----' + baseResURL() + imgURL[i]);
					mySwiper.addSlide(i, '<div class="swiper-slide"><img src="' + baseResURL() + imgURL[i] + '"></div>'); //在index为1的位置插入一个slide
				}
				//

				hui('.ImgTotal').html(imgURL.length);
				ImgPreview();

			}
			//添加视频方法
			function VideoIf(Video, VideoImg, SerialNo, ChannelNo) {
				var isVideo = (Video != null && Video != '');
				var isCamera = (caremaParams != null && caremaParams.length > 0);
				
				
				if (VideoImg){
					$('#video_Cover').attr('src', baseResURL() + VideoImg);
				}else{
					$('#video_Cover').attr('src', "img/videoFile.png");
				}

				if(isCamera) {
					//有rtsp视频流
					$('#play_Button').on('click', function() {
						openCamera();
					})
				} else if(isVideo) {
					//添加视频
					if(IsPlay == false) {
						myPlayer.pause(); //暂停
					}
					//$('#video_Cover').attr('src', baseResURL() + VideoImg);
					$('#play_Button').on('click', function() {
						localStorage.setItem('videoUrl', Video);
						localStorage.setItem('videoImg', VideoImg);
						localStorage.setItem('SerialNo', SerialNo);
						localStorage.setItem('ChannelNo', ChannelNo);
						hui.open('video_text.html', {}, true, {});
					})

				}

				/*var myPlayer =  videojs("#my-video");  //初始化视频
			        myPlayer.src(Video);  //重置video的src
			        myPlayer.load(Video);
				    myPlayer.on('play', function() {
	                    hui('.ImgVideoTab').hide();
	                });    
	                 //暂停--播放完毕后也会暂停
	                myPlayer.on('pause', function() {
	                    hui('.ImgVideoTab').show();
	                });*/

			}

			/*var huibackNum = 0;
				hui.Back = function() {
					if(huibackNum < 1) {
						hui.toast('再按一次退出程序');
						huibackNum++;
						setTimeout(function() {
							huibackNum = 0;
						}, 3000);
					} else {
						plus.runtime.quit();
					}
				}*/
		</script>

		<script type="text/javascript">
			function ImgPreview() {
				setTimeout(function() {
					var  objs  =  $(".swiper-container img");              
					for(var  i = 0; i < objs.length; i++)       {       
						objs[i].onclick = function()        {  
							var index = i;
							previewImg(index);     
						}      
					}  
					function previewImg(index) {
						var pswpElement = document.querySelectorAll('.pswp')[0];
						var items = [];
						//获取图片数据并填充近数组
						var  objs  = $(".swiper-container img");                     
						for(var  i = 0; i < objs.length; i++)           {  
							var eimg =  objs[i];            
							var imgObj = {
								src: eimg.getAttribute('src'),
								w: eimg.naturalWidth,
								h: eimg.naturalHeight
							};
							items.push(imgObj);        
						}  
						var options = {
							index: index
						};
						var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
						gallery.init();
					}
				}, 1500);
			}
		</script>

	</body>

</html>